home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / dancing_princess.swf / scripts / __Packages / mx / managers / DepthManager.as next >
Text File  |  2007-09-26  |  14KB  |  455 lines

  1. class mx.managers.DepthManager
  2. {
  3.    static var reservedDepth = 1048575;
  4.    static var highestDepth = 1048574;
  5.    static var lowestDepth = -16383;
  6.    static var numberOfAuthortimeLayers = 383;
  7.    static var kCursor = 101;
  8.    static var kTooltip = 102;
  9.    static var kTop = 201;
  10.    static var kBottom = 202;
  11.    static var kTopmost = 203;
  12.    static var kNotopmost = 204;
  13.    static var holder = _root.createEmptyMovieClip("reserved",mx.managers.DepthManager.reservedDepth);
  14.    static var __depthManager = new mx.managers.DepthManager();
  15.    function DepthManager()
  16.    {
  17.       MovieClip.prototype.createClassChildAtDepth = this.createClassChildAtDepth;
  18.       MovieClip.prototype.createChildAtDepth = this.createChildAtDepth;
  19.       MovieClip.prototype.setDepthTo = this.setDepthTo;
  20.       MovieClip.prototype.setDepthAbove = this.setDepthAbove;
  21.       MovieClip.prototype.setDepthBelow = this.setDepthBelow;
  22.       MovieClip.prototype.findNextAvailableDepth = this.findNextAvailableDepth;
  23.       MovieClip.prototype.shuffleDepths = this.shuffleDepths;
  24.       MovieClip.prototype.getDepthByFlag = this.getDepthByFlag;
  25.       MovieClip.prototype.buildDepthTable = this.buildDepthTable;
  26.    }
  27.    static function sortFunction(a, b)
  28.    {
  29.       if(a.getDepth() > b.getDepth())
  30.       {
  31.          return 1;
  32.       }
  33.       return -1;
  34.    }
  35.    static function test(depth)
  36.    {
  37.       if(depth == mx.managers.DepthManager.reservedDepth)
  38.       {
  39.          return false;
  40.       }
  41.       return true;
  42.    }
  43.    static function createClassObjectAtDepth(className, depthSpace, initObj)
  44.    {
  45.       var _loc1_ = undefined;
  46.       switch(depthSpace)
  47.       {
  48.          case mx.managers.DepthManager.kCursor:
  49.             _loc1_ = mx.managers.DepthManager.holder.createClassChildAtDepth(className,mx.managers.DepthManager.kTopmost,initObj);
  50.             break;
  51.          case mx.managers.DepthManager.kTooltip:
  52.             _loc1_ = mx.managers.DepthManager.holder.createClassChildAtDepth(className,mx.managers.DepthManager.kTop,initObj);
  53.       }
  54.       return _loc1_;
  55.    }
  56.    static function createObjectAtDepth(linkageName, depthSpace, initObj)
  57.    {
  58.       var _loc1_ = undefined;
  59.       switch(depthSpace)
  60.       {
  61.          case mx.managers.DepthManager.kCursor:
  62.             _loc1_ = mx.managers.DepthManager.holder.createChildAtDepth(linkageName,mx.managers.DepthManager.kTopmost,initObj);
  63.             break;
  64.          case mx.managers.DepthManager.kTooltip:
  65.             _loc1_ = mx.managers.DepthManager.holder.createChildAtDepth(linkageName,mx.managers.DepthManager.kTop,initObj);
  66.       }
  67.       return _loc1_;
  68.    }
  69.    function createClassChildAtDepth(className, depthFlag, initObj)
  70.    {
  71.       if(this._childCounter == undefined)
  72.       {
  73.          this._childCounter = 0;
  74.       }
  75.       var _loc3_ = this.buildDepthTable();
  76.       var _loc2_ = this.getDepthByFlag(depthFlag,_loc3_);
  77.       var _loc6_ = "down";
  78.       if(depthFlag == mx.managers.DepthManager.kBottom)
  79.       {
  80.          _loc6_ = "up";
  81.       }
  82.       var _loc5_ = undefined;
  83.       if(_loc3_[_loc2_] != undefined)
  84.       {
  85.          _loc5_ = _loc2_;
  86.          _loc2_ = this.findNextAvailableDepth(_loc2_,_loc3_,_loc6_);
  87.       }
  88.       var _loc4_ = this.createClassObject(className,"depthChild" + this._childCounter++,_loc2_,initObj);
  89.       if(_loc5_ != undefined)
  90.       {
  91.          _loc3_[_loc2_] = _loc4_;
  92.          this.shuffleDepths(_loc4_,_loc5_,_loc3_,_loc6_);
  93.       }
  94.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  95.       {
  96.          _loc4_._topmost = true;
  97.       }
  98.       return _loc4_;
  99.    }
  100.    function createChildAtDepth(linkageName, depthFlag, initObj)
  101.    {
  102.       if(this._childCounter == undefined)
  103.       {
  104.          this._childCounter = 0;
  105.       }
  106.       var _loc3_ = this.buildDepthTable();
  107.       var _loc2_ = this.getDepthByFlag(depthFlag,_loc3_);
  108.       var _loc6_ = "down";
  109.       if(depthFlag == mx.managers.DepthManager.kBottom)
  110.       {
  111.          _loc6_ = "up";
  112.       }
  113.       var _loc5_ = undefined;
  114.       if(_loc3_[_loc2_] != undefined)
  115.       {
  116.          _loc5_ = _loc2_;
  117.          _loc2_ = this.findNextAvailableDepth(_loc2_,_loc3_,_loc6_);
  118.       }
  119.       var _loc4_ = this.createObject(linkageName,"depthChild" + this._childCounter++,_loc2_,initObj);
  120.       if(_loc5_ != undefined)
  121.       {
  122.          _loc3_[_loc2_] = _loc4_;
  123.          this.shuffleDepths(_loc4_,_loc5_,_loc3_,_loc6_);
  124.       }
  125.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  126.       {
  127.          _loc4_._topmost = true;
  128.       }
  129.       return _loc4_;
  130.    }
  131.    function setDepthTo(depthFlag)
  132.    {
  133.       var _loc2_ = this._parent.buildDepthTable();
  134.       var _loc3_ = this._parent.getDepthByFlag(depthFlag,_loc2_);
  135.       if(_loc2_[_loc3_] != undefined)
  136.       {
  137.          this.shuffleDepths(this,_loc3_,_loc2_,undefined);
  138.       }
  139.       else
  140.       {
  141.          this.swapDepths(_loc3_);
  142.       }
  143.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  144.       {
  145.          this._topmost = true;
  146.       }
  147.       else
  148.       {
  149.          delete this._topmost;
  150.       }
  151.    }
  152.    function setDepthAbove(targetInstance)
  153.    {
  154.       if(targetInstance._parent != this._parent)
  155.       {
  156.          return undefined;
  157.       }
  158.       var _loc2_ = targetInstance.getDepth() + 1;
  159.       var _loc3_ = this._parent.buildDepthTable();
  160.       if(_loc3_[_loc2_] != undefined && this.getDepth() < _loc2_)
  161.       {
  162.          _loc2_ -= 1;
  163.       }
  164.       if(_loc2_ > mx.managers.DepthManager.highestDepth)
  165.       {
  166.          _loc2_ = mx.managers.DepthManager.highestDepth;
  167.       }
  168.       if(_loc2_ == mx.managers.DepthManager.highestDepth)
  169.       {
  170.          this._parent.shuffleDepths(this,_loc2_,_loc3_,"down");
  171.       }
  172.       else if(_loc3_[_loc2_] != undefined)
  173.       {
  174.          this._parent.shuffleDepths(this,_loc2_,_loc3_,undefined);
  175.       }
  176.       else
  177.       {
  178.          this.swapDepths(_loc2_);
  179.       }
  180.    }
  181.    function setDepthBelow(targetInstance)
  182.    {
  183.       if(targetInstance._parent != this._parent)
  184.       {
  185.          return undefined;
  186.       }
  187.       var _loc6_ = targetInstance.getDepth() - 1;
  188.       var _loc3_ = this._parent.buildDepthTable();
  189.       if(_loc3_[_loc6_] != undefined && this.getDepth() > _loc6_)
  190.       {
  191.          _loc6_ += 1;
  192.       }
  193.       var _loc4_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  194.       var _loc5_ = undefined;
  195.       for(_loc5_ in _loc3_)
  196.       {
  197.          var _loc2_ = _loc3_[_loc5_];
  198.          if(_loc2_._parent != undefined)
  199.          {
  200.             _loc4_ = Math.min(_loc4_,_loc2_.getDepth());
  201.          }
  202.       }
  203.       if(_loc6_ < _loc4_)
  204.       {
  205.          _loc6_ = _loc4_;
  206.       }
  207.       if(_loc6_ == _loc4_)
  208.       {
  209.          this._parent.shuffleDepths(this,_loc6_,_loc3_,"up");
  210.       }
  211.       else if(_loc3_[_loc6_] != undefined)
  212.       {
  213.          this._parent.shuffleDepths(this,_loc6_,_loc3_,undefined);
  214.       }
  215.       else
  216.       {
  217.          this.swapDepths(_loc6_);
  218.       }
  219.    }
  220.    function findNextAvailableDepth(targetDepth, depthTable, direction)
  221.    {
  222.       var _loc5_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  223.       if(targetDepth < _loc5_)
  224.       {
  225.          targetDepth = _loc5_;
  226.       }
  227.       if(depthTable[targetDepth] == undefined)
  228.       {
  229.          return targetDepth;
  230.       }
  231.       var _loc2_ = targetDepth;
  232.       var _loc1_ = targetDepth;
  233.       if(direction == "down")
  234.       {
  235.          while(depthTable[_loc1_] != undefined)
  236.          {
  237.             _loc1_ = _loc1_ - 1;
  238.          }
  239.          return _loc1_;
  240.       }
  241.       while(depthTable[_loc2_] != undefined)
  242.       {
  243.          _loc2_ = _loc2_ + 1;
  244.       }
  245.       return _loc2_;
  246.    }
  247.    function shuffleDepths(subject, targetDepth, depthTable, direction)
  248.    {
  249.       var _loc9_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  250.       var _loc8_ = _loc9_;
  251.       var _loc5_ = undefined;
  252.       for(_loc5_ in depthTable)
  253.       {
  254.          var _loc7_ = depthTable[_loc5_];
  255.          if(_loc7_._parent != undefined)
  256.          {
  257.             _loc9_ = Math.min(_loc9_,_loc7_.getDepth());
  258.          }
  259.       }
  260.       if(direction == undefined)
  261.       {
  262.          if(subject.getDepth() > targetDepth)
  263.          {
  264.             direction = "up";
  265.          }
  266.          else
  267.          {
  268.             direction = "down";
  269.          }
  270.       }
  271.       var _loc1_ = new Array();
  272.       for(_loc5_ in depthTable)
  273.       {
  274.          _loc7_ = depthTable[_loc5_];
  275.          if(_loc7_._parent != undefined)
  276.          {
  277.             _loc1_.push(_loc7_);
  278.          }
  279.       }
  280.       _loc1_.sort(mx.managers.DepthManager.sortFunction);
  281.       if(direction == "up")
  282.       {
  283.          var _loc3_ = undefined;
  284.          var _loc11_ = undefined;
  285.          while(_loc1_.length > 0)
  286.          {
  287.             _loc3_ = _loc1_.pop();
  288.             if(_loc3_ == subject)
  289.             {
  290.                break;
  291.             }
  292.          }
  293.          while(_loc1_.length > 0)
  294.          {
  295.             _loc11_ = subject.getDepth();
  296.             _loc3_ = _loc1_.pop();
  297.             var _loc4_ = _loc3_.getDepth();
  298.             if(_loc11_ > _loc4_ + 1)
  299.             {
  300.                if(_loc4_ >= 0)
  301.                {
  302.                   subject.swapDepths(_loc4_ + 1);
  303.                }
  304.                else if(_loc11_ > _loc8_ && _loc4_ < _loc8_)
  305.                {
  306.                   subject.swapDepths(_loc8_);
  307.                }
  308.             }
  309.             subject.swapDepths(_loc3_);
  310.             if(_loc4_ == targetDepth)
  311.             {
  312.                break;
  313.             }
  314.          }
  315.       }
  316.       else if(direction == "down")
  317.       {
  318.          _loc3_ = undefined;
  319.          while(_loc1_.length > 0)
  320.          {
  321.             _loc3_ = _loc1_.shift();
  322.             if(_loc3_ == subject)
  323.             {
  324.                break;
  325.             }
  326.          }
  327.          while(_loc1_.length > 0)
  328.          {
  329.             _loc11_ = _loc3_.getDepth();
  330.             _loc3_ = _loc1_.shift();
  331.             _loc4_ = _loc3_.getDepth();
  332.             if(_loc11_ < _loc4_ - 1 && _loc4_ > 0)
  333.             {
  334.                subject.swapDepths(_loc4_ - 1);
  335.             }
  336.             subject.swapDepths(_loc3_);
  337.             if(_loc4_ == targetDepth)
  338.             {
  339.                break;
  340.             }
  341.          }
  342.       }
  343.    }
  344.    function getDepthByFlag(depthFlag, depthTable)
  345.    {
  346.       var _loc2_ = 0;
  347.       if(depthFlag == mx.managers.DepthManager.kTop || depthFlag == mx.managers.DepthManager.kNotopmost)
  348.       {
  349.          var _loc5_ = 0;
  350.          var _loc7_ = false;
  351.          var _loc8_ = undefined;
  352.          for(_loc8_ in depthTable)
  353.          {
  354.             var _loc9_ = depthTable[_loc8_];
  355.             var _loc3_ = typeof _loc9_;
  356.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  357.             {
  358.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  359.                {
  360.                   if(!_loc9_._topmost)
  361.                   {
  362.                      _loc2_ = Math.max(_loc2_,_loc9_.getDepth());
  363.                   }
  364.                   else if(!_loc7_)
  365.                   {
  366.                      _loc5_ = _loc9_.getDepth();
  367.                      _loc7_ = true;
  368.                   }
  369.                   else
  370.                   {
  371.                      _loc5_ = Math.min(_loc5_,_loc9_.getDepth());
  372.                   }
  373.                }
  374.             }
  375.          }
  376.          _loc2_ += 20;
  377.          if(_loc7_)
  378.          {
  379.             if(_loc2_ >= _loc5_)
  380.             {
  381.                _loc2_ = _loc5_ - 1;
  382.             }
  383.          }
  384.       }
  385.       else if(depthFlag == mx.managers.DepthManager.kBottom)
  386.       {
  387.          for(_loc8_ in depthTable)
  388.          {
  389.             _loc9_ = depthTable[_loc8_];
  390.             _loc3_ = typeof _loc9_;
  391.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  392.             {
  393.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  394.                {
  395.                   _loc2_ = Math.min(_loc2_,_loc9_.getDepth());
  396.                }
  397.             }
  398.          }
  399.          _loc2_ -= 20;
  400.       }
  401.       else if(depthFlag == mx.managers.DepthManager.kTopmost)
  402.       {
  403.          for(_loc8_ in depthTable)
  404.          {
  405.             _loc9_ = depthTable[_loc8_];
  406.             _loc3_ = typeof _loc9_;
  407.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  408.             {
  409.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  410.                {
  411.                   _loc2_ = Math.max(_loc2_,_loc9_.getDepth());
  412.                }
  413.             }
  414.          }
  415.          _loc2_ += 100;
  416.       }
  417.       if(_loc2_ >= mx.managers.DepthManager.highestDepth)
  418.       {
  419.          _loc2_ = mx.managers.DepthManager.highestDepth;
  420.       }
  421.       var _loc6_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  422.       for(_loc9_ in depthTable)
  423.       {
  424.          var _loc4_ = depthTable[_loc9_];
  425.          if(_loc4_._parent != undefined)
  426.          {
  427.             _loc6_ = Math.min(_loc6_,_loc4_.getDepth());
  428.          }
  429.       }
  430.       if(_loc2_ <= _loc6_)
  431.       {
  432.          _loc2_ = _loc6_;
  433.       }
  434.       return _loc2_;
  435.    }
  436.    function buildDepthTable(Void)
  437.    {
  438.       var _loc5_ = new Array();
  439.       var _loc4_ = undefined;
  440.       for(_loc4_ in this)
  441.       {
  442.          var _loc2_ = this[_loc4_];
  443.          var _loc3_ = typeof _loc2_;
  444.          if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc2_.__getTextFormat != undefined)
  445.          {
  446.             if(_loc2_._parent == this)
  447.             {
  448.                _loc5_[_loc2_.getDepth()] = _loc2_;
  449.             }
  450.          }
  451.       }
  452.       return _loc5_;
  453.    }
  454. }
  455.